Page({
  data:{
    currentTab:0,
    indicatorDots:false,
    autoplay:true,
    interval:5000,
    duration:1000,
    imgUrls:[
      '/img/haibao/1.jpg',
      '/img/haibao/2.jpg',
      '/img/haibao/3.jpg',
      '/img/haibao/4.jpg'
    ],
    movies:[],
    will:[],
    flag:0
  },
  onLoad:function(e){
    this.loadMovies();
  },
  switchNav:function(e){
    var page = this;
    var index = e.target.dataset.current;
    if(this.data.currentTab == index){
       return false;
    }else{
      page.setData({currentTab:index});
    }
  },
  loadMovies:function(){
    var page = this;
    wx.request({
      url: 'http://127.0.0.1:8080/findAllOnlineFilms_wx',
      method:'GET',
      header:{
        "Content-Type":"json"
      },
      success:function(res){
         console.log(res);
         var movies = new Array();
         var subjects = res.data.data;
         var len = subjects.length >=10?10:subjects.length;
         for(var i=0;i<len;i++){
            var subject = subjects[i];
            var movie = new Object();
            //电影名称
            movie.name = subject.Film_name;

            //电影海报图片
            movie.pic = "../"+subject.Url;

            //导演
            var director = subject.Director;
            //var dir = '';
            /*for(var j=0;j<directors.length;j++){
               dir += directors[j].name + ' ';
            }*/
            movie.dir = director;

            //主演
            var casts = subject.Actor;
           // var cast = '';
           /* for(var j=0;j<casts.length;j++){
                cast += casts[j].name + ' ';
            }*/
            movie.cast = casts;
            movie.id = subject.Film_id;
           // movie.year = subject.year;
            //影片类型
            var genres = subject.Film_type;
            //var gen = '';
           /* for(var j=0;j<genres.length;j++){
               gen += genres[j]+' ';
            }*/
            movie.type = genres;
            movies.push(movie);

         }
         console.log(movies);
         page.setData({movies:movies});
      }
    })
    wx.request({
      url: 'http://127.0.0.1:8080/findAllforthcomingFilms_wx',
      method:'GET',
      header:{
        "Content-Type":"json"
      },
      success:function(res){
         console.log(res);
         var will = new Array();
         var subjects = res.data.data;
         var len = subjects.length >=10?10:subjects.length;
         for(var i=0;i<len;i++){
            var subject = subjects[i];
            var movie = new Object();
            //电影名称
            movie.name = subject.Film_name;
            //电影海报图片
            movie.pic = "../"+subject.Url;
            //导演
            var director = subject.Director;
            movie.dir = director;
            //主演
            var casts = subject.Actor;
            movie.cast = casts;
            movie.id = subject.Film_id;
            //影片类型
            var genres = subject.Film_type;
            movie.type = genres;
            will.push(movie);

         }
         console.log(will);
         page.setData({will:will});
      }
    })
  },
  switchMonth:function(e){
     var page = this;
     var id = e.target.id;
     if(this.data.flag == id){
        return false;
     }else{
       page.setData({flag:id});
     }
  },
  loadMovieDetail:function(e){
    console.log(e);
    var app=getApp()
    var username=app.globalData.username
    if(username==null){
      wx.showToast({
        title: '请先登录',
        icon: 'none',
        duration: 1500
    })   
    }else{
      var id = e.currentTarget.id;
      wx.navigateTo({
        url: '../movieDetail/movieDetail?id='+id
      })
    }

  }
})